//
//  STDoorAdrCell.m
//  YiYueHairdresser
//
//  Created by zhouzhouzhou on 2018/10/9.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STDoorAdrCell.h"
#import "UILabel+LeftTopAlign.h"

@implementation STDoorAdrCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    self = [[[NSBundle mainBundle] loadNibNamed:@"STDoorAdrCell" owner:nil options:nil] lastObject];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    return self;
}

-(void)setDoorAdrInfoWith:(STDoorLocalModel *)adrData{
    self.addressText.text = adrData.location;
    if (!adrData.distance) {
        self.distanceLab.hidden = YES;
    }else{
        self.distanceLab.hidden = NO;
        self.distanceLab.text = [NSString stringWithFormat:@"(距您%ldm)",adrData.distance];
        [self setDistanceLabFrame];
    }
    
    
}

-(void)setDistanceLabFrame{
    CGPoint lastPoint = [self getLastStringPoint];
    self.distanceConstraint.constant = lastPoint.x+10;
//    self.distanceLab.frame = CGRectMake( self.distanceLab.origin.y, CGRectGetWidth(self.distanceLab.frame), CGRectGetHeight(self.distanceLab.frame));
}

-(CGPoint )getLastStringPoint{
    CGPoint lastPoint;
    CGSize sz = [self.addressText.text sizeWithFont:self.addressText.font constrainedToSize:CGSizeMake(SCREEN_WIDTH-40-15, 40)];
    
    CGSize linesSz = [self.addressText.text sizeWithFont:self.addressText.font constrainedToSize:CGSizeMake(self.addressText.frame.size.width, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
    
    if(sz.width <= linesSz.width) //判断是否折行
    {
//        lastPoint = CGPointMake(self.addressText.frame.origin.x + sz.width, self.addressText.frame.origin.y);
        lastPoint = CGPointMake(25, 20);
        
    }else{
         lastPoint = CGPointMake(self.addressText.frame.origin.x + (int)sz.width % (int)linesSz.width,linesSz.height - sz.height);
        
    }
    return lastPoint;
    
}

@end
